<!-- f r o m 7 5  2 7 1  8 9 2 0 -->
<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <!-- 搜索区域 -->
          <a-form layout="inline" @keyup.enter.native="searchQuerytest">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item label="产品类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select
                    placeholder="选择产品类型"
                    showSearch
                    allowClear
                    optionFilterProp="children"
                    v-model="queryParam.productType"
                  >
                    <a-select-option v-for="(item, index) in purchaseTest" :key="index" :value="item.typeId">
                      {{ item.typeName }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="检验日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-range-picker
                    style="width: 100%"
                    :placeholder="['开始时间', '结束时间']"
                    v-model="queryParam.createTime"
                    @change="onDateChange"
                    format="YYYY-MM-DD"
                  />
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="客户" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-model="queryParam.vendor" placeholder="请输入客户名称"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="不合格内容" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-model="queryParam.unqualifiedContent" placeholder="请输入不合格内容"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="检验处置" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-model="queryParam.disposal" placeholder="请输入检验处置"></a-input>
                </a-form-item>
              </a-col>
              <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                <a-col :md="6" :sm="24">
                  <a-button type="primary" @click="searchQuerytest">查询</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
                </a-col>
              </span>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" style="margin: 5px 0px">
          <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
        </div>
        <!-- table区域-begin -->
        <div>
          <!--          :scroll="scroll"-->
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :scroll="{ x: 1600, y: 800 }"
            :loading="loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            @change="handleTableChange"
          >
            <span slot="action" slot-scope="text, record">
              <a @click="handleSee(record)">查看</a>
              <a-divider type="vertical" />
              <a @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical" />
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.testId)">
                <a>删除</a>
              </a-popconfirm>
            </span>
            <!-- 状态渲染模板 -->
            <template slot="customRenderFlag" slot-scope="enabled">
              <a-tag v-if="enabled" color="green">启用</a-tag>
              <a-tag v-if="!enabled" color="orange">禁用</a-tag>
            </template>
            <!-- 状态渲染模板 -->
            <template slot="attributes" slot-scope="text, record">
              <div>
                {{   record.attributes
                    ? record.attributes
                        .split('{')
                        .join('')
                        .split('}')
                        .join('')
                        .split('"')
                        .join('')
                    : record.attributes }}
              </div>
            </template>
            <template slot="qualifiedRate" slot-scope="text, record">
              <div>
                {{ Number(record.qualifiedRate) / 100 }}
              </div>
            </template>
            <template slot="productType" slot-scope="text, record">
              <div v-for="(item, index) in purchaseTest" :key="index">
                {{ record.productType == item.typeId ? item.typeName : '' }}
              </div>
            </template>
          </a-table>
        </div>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <customer-modal ref="modalForm" @ok="modalFormOk"></customer-modal>
      </a-card>
    </a-col>
  </a-row>
</template>
<!-- BY cao_yu_li -->
<script>
import CustomerModal from './modules/CustomerModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { openDownloadDialog, sheet2blob } from '@/utils/util'
import { getDateList, fuzzyQuery } from '@/api/api'
import JDate from '@/components/jeecg/JDate'
export default {
  name: 'Process',
  mixins: [JeecgListMixin],
  components: {
    CustomerModal,
    JDate
  },
  data() {
    return {
      labelCol: {
        span: 5
      },
      wrapperCol: {
        span: 18,
        offset: 1
      },
      // 查询条件
      queryParam: {
        supplier: '',
        type: '客户',
        telephone: '',
        phonenum: ''
      },
      ipagination: {
        pageSizeOptions: ['10', '20', '30', '100', '200']
      },
      purchaseTest: [],
      purchaseType: ['维修', '退货', '客户授权'],
      processTest: ['内部机加', '清洗', '喷砂', '表面', '涂层'],
      processType: ['返工', '报废', '让步放行'],
      finalTest: ['校型', '打标', '包装'],
      finalType: ['修补', '返工', '退货', '报废', '客户授权', '让步放行'],
      // 表头
      columns: [
        // {
        //   title: '#',
        //   dataIndex: '',
        //   key:'rowIndex',
        //   width:60,
        //   align:"center",
        //   customRender:function (t,r,index) {
        //     return parseInt(index)+1;
        //   }
        // },
        {
          title: '产品类型',
          key: '1',
          dataIndex: 'productType',
          width: 120,
          align: 'center',
          scopedSlots: { customRender: 'productType' }
        },
        { title: '检验日期', key: '11', dataIndex: 'testDate', width: 120, align: 'center' },
        { title: '任务单号', key: '12', dataIndex: 'voucher', width: 100, align: 'center' },
        { title: '产品名称', key: '13', dataIndex: 'productName', width: 120, align: 'center' },
        { title: '客户', key: '20', dataIndex: 'vendor', width: 120, align: 'center' },
        {
          title: '规格型号',
          key: '14',
          dataIndex: 'attributes',
          width: 180,
          align: 'center',
          scopedSlots: { customRender: 'attributes' }
        },
        { title: '检验数量', key: '15', dataIndex: 'testNum', width: 100, align: 'center' },
        { title: '不合格数量', key: '16', dataIndex: 'unqualifiedNum', width: 100, align: 'center' }, // 自动统计
        {
          title: '过程检验合格率(%)',
          key: '18',
          dataIndex: 'qualifiedRate',
          width: 100,
          align: 'center',
          scopedSlots: { customRender: 'qualifiedRate' }
        }, // 自动统计
        { title: '不合格内容', key: '17', dataIndex: 'unqualifiedContent', width: 180, align: 'center' },
        { title: '检验处置', key: '19', dataIndex: 'disposal', width: 150, align: 'center' },
        {
          title: '操作',
          dataIndex: 'action',
          width: 150,
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/testReport/getList',
        delete: '/testReport/remove',
        deleteBatch: '/supplier/deleteBatch',
        importExcelUrl: '/supplier/importCustomer',
        exportXlsUrl: '/supplier/exportExcel',
        batchSetStatusUrl: '/supplier/batchSetStatus'
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}${this.url.importExcelUrl}`
    }
  },
  mounted() {
    getDateList({ testType: this.$router.currentRoute.name }).then(res => {
      if ((res.code = 10000)) {
        console.log(res.data.records)
        this.purchaseTest = res.data.records
      }
    })
  },
  methods: {
    //日期
    onDateChange: function(value, dateString) {
      this.queryParam.startTime = dateString[0]
      this.queryParam.endTime = dateString[1]
      console.log(this.queryParam)
    },
    //模糊查询--不走公共
    searchQuerytest() {
      this.queryParam.testType = '过程检验'
      var { ...params } = this.queryParam
      console.log(params)
      fuzzyQuery(params).then(res => {
        if (res.code == 10000 || res.code == 200) {
          this.dataSource = res.data.records
        }
      })
    },
    handleSee(record) {
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '查看'
      this.$refs.modalForm.disableSubmit = true
      if (this.btnEnableList.indexOf(1) === -1) {
        this.$refs.modalForm.isReadOnly = true
      }
    },
    searchReset() {
      this.queryParam = {
        type: '客户'
      }
      this.loadData(1)
    },
    handleEdit: function(record) {
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '编辑'
      this.$refs.modalForm.disableSubmit = false
      if (this.btnEnableList.indexOf(1) === -1) {
        this.$refs.modalForm.isReadOnly = false
      }
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
